package edu.jkd.controller;


import edu.jkd.entity.Company;
import edu.jkd.entity.User;
import edu.jkd.service.ICompanyService;
import edu.jkd.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zhaojianyun
 * @since 2022-11-28
 */
@Controller
public class UserController {
    @Autowired
    private IUserService userService;
    @Autowired
    private ICompanyService companyService;



    @PostMapping("login")
    public ModelAndView Login(String user, String pwd) {
        ModelAndView mav = new ModelAndView();
        List<User> users = userService.list(null);
        for (User user1 : users) {
            if (user1.getUsername().equals(user) && user1.getPassword().equals(pwd)) {
                List<Company> companyList = companyService.list(null);
                mav.addObject("companyList", companyList);
                mav.addObject("user1",user1);
                mav.setViewName("zhaoping2");
                return mav;
            }
        }
        mav.addObject("message", "用户名或密码错误");
        mav.setViewName("zhaoping");
        return mav;
    }



}
